﻿/*
 ***********************************
 时间：2017.8.22
 代码：WangSir
 脚本作用：当局游戏结束的插屏和五星评价
 ************************************
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Beyond;
using System;
using ZJ_WangSir;
using MyIdolUIFrameWork;
using Rosiness;

/// <summary>当局游戏结束的插屏和五星评价 </summary>
public class InsAdEvaluate : MonoSingleton<InsAdEvaluate>,IModule
{
    // public static InsAdEvaluate instance;
    DateTime dt;


    private void Awake()
    {
        // if (instance == null) instance = this;
        // else if (instance != this) Destroy(gameObject);
        // DontDestroyOnLoad(gameObject);
    }
    private void Start()
    {
        dt = DateTime.Now;
    }
    private void Update()
    {

    }

    /// <summary>显示插屏或者评价 </summary>
    public void  ShowInsAdOrReview()
    {
        GameState.playingTimes++;
        int pjkz_Value = AppInfo.getSetting("pjkz", 0);  
        int cpkz_Value = AppInfo.getSetting("cpkz", 0); 
        bool bEvaluate = CPlayerPrefs.GetInt("evaluate_1") == App.getAppVersion();
        if (!bEvaluate && pjkz_Value != 0 && (DateTime.Now - dt).TotalMilliseconds >= (pjkz_Value * 60 * 1000) && GameState.is5StarsDialogTrue == false)
        {
            GameState.is5StarsDialogTrue = true;
            //EvaluateAwardController.Instance.OpenEvaluateDialog();             //五星评论提示
            UIManager.Instance.SetVisible(UIName.UIEvaluate, true);
        }
        else
        {
            if ((GameState.playingTimes % 2 != 0) && (cpkz_Value == 0))
            {
                return;
            }
            ZJ_WangSir.CUtils.ShowInterstitialAd(); //插屏广告
        }
    }

    /// <summary>单纯检测评价</summary>
    public void OnlyShowEvaluate()
    {
        int pjkz_Value = AppInfo.getSetting("pjkz", 0);
        bool bEvaluate = CPlayerPrefs.GetInt("evaluate_1") == App.getAppVersion();
        if(!bEvaluate && pjkz_Value!=0 && (DateTime.Now-dt).TotalMilliseconds>=(pjkz_Value*60*1000) && GameState.is5StarsDialogTrue==false)
        {
            GameState.is5StarsDialogTrue = true;
            EvaluateAwardController.Instance.OpenEvaluateDialog(); 
        }
    }

    /// <summary>单独插屏广告，受开关控制影响</summary>
    public void OnlyShowInterstitialAd()
    {
        BELog.debug("插屏*-*-*-*-*-*-");
        GameState.playingTimes++;
        int cpkz_Value = AppInfo.getSetting("cpkz", 0);
        if ((GameState.playingTimes % 2 != 0) && (cpkz_Value == 0))
        {
            return;
        }
        ZJ_WangSir.CUtils.ShowInterstitialAd();
    }


    /// <summary>
    /// 单独插屏不受开关控制
    /// </summary>
    public void OnlyInAdWithoutToggle()
    {
        BELog.debug("插屏*-*-*-*-*-*-");
        ZJ_WangSir.CUtils.ShowInterstitialAd();
    }

    public void OnCreate(object createParam)
    {
    }

    public void OnUpdate()
    {
    }

    public void OnGUI()
    {
    }
}
